/** \file
* Declaration of the curl globals class.
* This file is part of Chorus, available at
* http://code.google.com/p/chorus-twitter/ . This file and all associated files
* and derivative works are bound by the terms of the LGPL 3.0 license,
* available at http://www.gnu.org/licenses/lgpl-3.0-standalone.html .
* \par Subversion URL:
* \$URL: http://chorus-twitter.googlecode.com/svn/branches/cpp/src/system/CurlGlob.hpp $
* \version \$Rev: 152 $
* \date    \$Date: 2010-04-06 07:35:13 +0000 (Tue, 06 Apr 2010) $
*/

#pragma once

#include <curl/curl.h>

#include "system/Mutex.hpp"

/// Contains the global curl handles and global setup/teardown.
class CurlGlob
{
public:
	/// The constructor.
	CurlGlob();

	/// The destructor.
	~CurlGlob();

public:
	/// Get the curl share pointer.
	/// \return The curl share pointer.
	CURLSH *getShare() const
	{
		return curlshare;
	}

	/// The curl share data lock callback.
	/// \param handle  The associated handle (ignored).
	/// \param data    The data type being locked.
	/// \param access  The requested access (ignored).
	/// \param userptr The this-pointer.
	static void lockCallback(CURL *handle, curl_lock_data data,
		curl_lock_access access, void *userptr);

	/// The curl share data lock routine.
	/// \param data    The data type being locked.
	void lockData(curl_lock_data data);

	/// The curl share data unlock callback.
	/// \param handle  The associated handle (ignored).
	/// \param data    The data type being locked.
	/// \param userptr The this-pointer.
	static void unlockCallback(CURL *handle, curl_lock_data data,
		void *userptr);

	/// The curl share data unlock routine.
	/// \param data The data type being locked.
	void unlockData(curl_lock_data data);

private:
	/// The curl share pointer.
	CURLSH *curlshare;
	/// The array of curl data locking mutexes.
	Mutex datamutexes[CURL_LOCK_DATA_LAST];
};
